<?php

class AskModel extends Model {

	public $table = '360_ask';

	// 查询所有的问题
	public function AllAsk(){
		$Count = $this->count();
		$Page = new Page($Count,10);
		$PageList = $Page->show_b();
		$Limit = $Page->limit();
		$Sql = "SELECT
		ask.ask_id,
		COUNT(*) AS count,
		ask.ask_content,ask.ask_gold,
		ask.ask_time,
		ans.ans_content
		FROM
		360_ask AS ask
		LEFT JOIN 360_ans AS ans ON ask.ask_id = ans.ask_id
		GROUP BY ask.ask_id  ORDER BY ask.ask_id DESC LIMIT {$Limit}";
		 $AskList = $this->query($Sql);
		return array('AskList'=>$AskList,'Pages'=>$PageList,'count'=>$Count);
	}

	public function WhiteAsk(){
		// 条数
		$CSql = "SELECT COUNT(*) AS c FROM 360_ask AS ask 
		LEFT JOIN 360_accept AS accept ON ask.ask_id = accept.ask_id
		WHERE id IS NULL";
		$Counts = $this->query($CSql);
		$Count = $Counts[0]['c'];
		// 实例化分页类
		$Page = new Page($Count,10);
		// 页码方法
		$PageList = $Page->show_b();
		// LIMIT 条数
		$Limit = $Page->limit();
		// 待解决问题列表SQL
		$Sql = " SELECT * FROM 360_ask AS ask 
		LEFT JOIN 360_accept AS accept
		 ON ask.ask_id = accept.ask_id
		 WHERE id IS NULL
		 GROUP BY ask.ask_id  ORDER BY ask.ask_id DESC LIMIT {$Limit}";
		 $AskList = $this->query($Sql);
		 return array('count'=>$Count,'Pages'=>$PageList,'AskList'=>$AskList);
	}

	public function SettleAsk(){
		// 条数
		$CSql = "SELECT count(*)AS c FROM 360_ask AS ask 
		INNER JOIN 360_accept AS accept
		ON ask.ask_id = accept.ask_id WHERE
		ask.ask_id IS NOT NULL";
		$Counts = $this->query($CSql);
		$Count = $Counts[0]['c'];
		// 实例化分页类
		$Page = new Page($Count,10);
		// 页码方法
		$PageList = $Page->show_b();
		// LIMIT 条数
		$Limit = $Page->limit();
		// 已决问题列表SQL
		$Sql = " SELECT * FROM 360_ask AS ask
		INNER JOIN 360_ans AS ans 
		ON ask.ask_id = ans.ask_id INNER JOIN 360_accept AS accept 
		ON ask.ask_id = accept.ask_id
		GROUP BY ask.ask_id  ORDER BY ask.ask_id DESC LIMIT {$Limit}";
		 $AskList = $this->query($Sql);
		 return array('count'=>$Count,'Pages'=>$PageList,'AskList'=>$AskList);
	}
	public function NoAnswerAsk(){
		// 条数
		$CSql = "SELECT count(*) AS c
		FROM 360_ask AS ask 
		LEFT JOIN 360_ans AS ans 
		ON ask.ask_id = ans.ask_id
		WHERE ans.ans_id IS NULL;";
		$Counts = $this->query($CSql);
		$Count = $Counts[0]['c'];
		// 实例化分页类
		$Page = new Page($Count,10);
		// 页码方法
		$PageList = $Page->show_b();
		// LIMIT 条数
		$Limit = $Page->limit();
		// 没有回答的问题列表SQL
		$Sql = " SELECT ask_content,ask_time,ask_gold
		FROM 360_ask AS ask 
		LEFT JOIN 360_ans AS ans 
		ON ask.ask_id = ans.ask_id
		WHERE ans.ans_id IS NULL  ORDER BY ask.ask_id DESC LIMIT {$Limit}";

		 $AskList = $this->query($Sql);
		 return array('count'=>$Count,'Pages'=>$PageList,'AskList'=>$AskList);
	}
}


?>